package com.hxkcloud.nurse.activitys;

import android.content.Context;
import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.resultbeans.BaseResultBean;
import com.hxkcloud.nurse.request.MessageCode;
import com.hxkcloud.nurse.request.YiJiaHuNetWorkUtils;

/**
 * Created by ray_lei on 2016/7/26.
 */
public class CommentActivity extends BaseActivity implements View.OnClickListener {

//    private LinearLayout ll_title;
//    private ImageView iv_back;
//    private TextView tv_title;

    private EditText et_comment;
    private Button btn_submit;

    private BaseResultBean resultBean;
    private View view_back;
    private String articleId;
    private String acctType;

    @Override
    protected void updateByHandler(Message msg) {
        switch (msg.what) {
            case MessageCode.NETWORKCODE_COMMENTARTICALINFO_SUCCESS:
                if (msg.obj != null) {
                    resultBean = (BaseResultBean) msg.obj;
                    toastMsg(resultBean.getMessage());
                    finish();
                }

                break;
            case MessageCode.NETWORKCODE_COMMENTARTICALINFO_FAILURE:
                if (msg.obj != null) {
                    toastMsg(msg.obj.toString());
                    return;
                }

                break;

        }

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_comment);

        articleId = getIntent().getStringExtra("articleId");
        acctType = getIntent().getStringExtra("acctType");
        if (TextUtils.isEmpty(articleId)) {
            finish();
        }

        initView();
        initData();
        initListener();
    }

    @Override
    protected void initView() {

//        ll_title = (LinearLayout) findViewById(R.id.ll_title);
//        iv_back = (ImageView) findViewById(R.id.iv_title_back);
//        tv_title = (TextView) findViewById(R.id.tv_title_title);
//        setTitlePadding(ll_title);
//        iv_back.setVisibility(View.VISIBLE);
//        tv_title.setText(getResources().getText(R.string.comment_text_title));
        view_back = findViewById(R.id.view_back);
        et_comment = (EditText) findViewById(R.id.et_comment);



        btn_submit = (Button) findViewById(R.id.comment_btn_submit);
    }

    @Override
    protected void initListener() {
//        iv_back.setOnClickListener(this);
        view_back.setOnClickListener(this);
        btn_submit.setOnClickListener(this);

    }

    @Override
    protected void initData() {
        et_comment.setFocusable(true);
        et_comment.setFocusableInTouchMode(true);
        et_comment.requestFocus();
        InputMethodManager imm = (InputMethodManager)CommentActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.view_back:
                if (TextUtils.isEmpty(et_comment.getText().toString().trim())){
                    finish();
                }else {
                    toastMsg("是否发送回复?");
                    return;
                }
                break;
            case R.id.comment_btn_submit:
                String content = et_comment.getText().toString();
                if (TextUtils.isEmpty(content)) {
                    toastMsg(this.getResources().getString(R.string.pleaseinputcontent));
                    return;
                }
                YiJiaHuNetWorkUtils.commentArtical(articleId, content, acctType, handler);
                break;
        }
    }
}
